home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / QDDVX102.ZIP / contrib / dvx / inc / x11 / xlibint.h < prev    next >
Text File  |  1993-07-15  |  16KB  |  550 lines

  1. /* $XConsortium: Xlibint.h,v 11.79 89/12/12 12:13:42 jim Exp $ */
  2. /* Copyright 1984, 1985, 1987, 1989  Massachusetts Institute of Technology */
  3.  
  4. /*
  5.  *    XlibInternal.h - Header definition and support file for the internal
  6.  *    support routines (XlibInternal) used by the C subroutine interface
  7.  *    library (Xlib) to the X Window System.
  8.  *
  9.  *    Warning, there be dragons here....
  10.  */
  11.  
  12. #include <X11/copyright.h>
  13.  
  14. #ifndef NEED_EVENTS
  15. #define _XEVENT_
  16. #endif
  17.  
  18. #ifdef USG
  19. #ifndef __TYPES__
  20. #include <sys/types.h>            /* forgot to protect it... */
  21. #define __TYPES__
  22. #endif /* __TYPES__ */
  23. #else
  24. #include <sys/types.h>
  25. #endif /* USG */
  26.  
  27. /*
  28.  * define the following if you want the Data macro to be a procedure instead
  29.  */
  30. #if defined(CRAY)
  31. #define DataRoutineIsProcedure
  32. #endif /* CRAY */
  33.  
  34. #include <X11/Xlib.h>        /* get NeedFunctionPrototypes defs */
  35.  
  36. #if NeedFunctionPrototypes    /* prototypes require event type definitions */
  37. #define NEED_EVENTS
  38. #endif
  39. #include <X11/Xproto.h>
  40. #include <errno.h>
  41. #if (!defined(EPIPE)) || (EPIPE == -1) /* __WATCOMC__              MJCR/POHC 91/03/01 */
  42. #undef EPIPE
  43. #define EPIPE 32
  44. #endif
  45. #if (!defined(EINTR)) || (EINTR == -1) /* __ZORTECH__ POHC 91/03/05 */
  46. #undef EINTR
  47. #define EINTR 4 /* Interrupted system call. */
  48. #endif
  49. #include <X11/Xlibos.h>
  50.  
  51. #ifdef __cplusplus            /* do not leave open across includes */
  52. extern "C" {                    /* for C++ V2.0 */
  53. #endif
  54.  
  55. #include <sys\param.h>
  56.  
  57. #define LOCKED 1
  58. #define UNLOCKED 0
  59.  
  60. #ifndef MSDOS /* 90/06/22 POHC */
  61. extern void bcopy();
  62. #endif
  63.  
  64. extern int _XError();            /* prepare to upcall user handler */
  65. extern int _XIOError();            /* prepare to upcall user handler */
  66. extern int (*_XIOErrorFunction)(
  67. #if (NeedFunctionPrototypes || NeedFunctionPtrPrototypes) /* POHC 91/04/16 */
  68. Display * /* POHC 91/04/16 */
  69. #endif
  70. );    /* X system error reporting routine. */
  71. extern int (*_XErrorFunction)(
  72. #if (NeedFunctionPrototypes || NeedFunctionPtrPrototypes) /* POHC 91/04/16 */
  73. Display *,struct _XErrorEvent * /* POHC 91/04/16 */
  74. #endif
  75. );    /* X_Error event reporting routine. */
  76. extern void _XEatData();        /* swallow data from server */
  77. extern char *_XAllocScratch();        /* fast memory allocator */
  78. extern Visual *_XVIDtoVisual();        /* given visual id, find structure */
  79. extern unsigned long _XSetLastRequestRead();    /* update dpy->last_request_read */
  80. extern int _XGetHostname();        /* get name of this machine */
  81. extern Screen *_XScreenOfWindow ();    /* get Screen pointer for window */
  82.  
  83. #if !BUFSIZE && !__HIGHC__ /* defined in stdio.h - included later. 90/06/18 POHC */
  84. #define BUFSIZE 2048            /* X output buffer size. */
  85. #endif
  86. #ifndef EPERBATCH
  87. #define EPERBATCH 8            /* when batching, how many elements */
  88. #endif
  89. #ifndef CURSORFONT
  90. #define CURSORFONT "cursor"        /* standard cursor fonts */
  91. #endif
  92.  
  93. /*
  94.  * display flags
  95.  */
  96. #define XlibDisplayIOError    (1L << 0)
  97. #define XlibDisplayClosing    (1L << 1)
  98.  
  99. /*
  100.  * X Protocol packetizing macros.
  101.  */
  102.  
  103. /*   Need to start requests on 64 bit word boundries
  104.  *   on a CRAY computer so add a NoOp (127) if needed.
  105.  *   A character pointer on a CRAY computer will be non-zero
  106.  *   after shifting right 61 bits of it is not pointing to
  107.  *   a word boundary.
  108.  */
  109. #ifdef WORD64
  110. #define WORD64ALIGN if ((long)dpy->bufptr >> 61) {\
  111.            dpy->last_req = dpy->bufptr;\
  112.            *(dpy->bufptr)   = X_NoOperation;\
  113.            *(dpy->bufptr+1) =  0;\
  114.            *(dpy->bufptr+2) =  0;\
  115.            *(dpy->bufptr+3) =  1;\
  116.              dpy->request += 1;\
  117.              dpy->bufptr += 4;\
  118.          }
  119. #else /* else does not require alignment on 64-bit boundaries */
  120. #define WORD64ALIGN
  121. #endif /* WORD64 */
  122.  
  123.  
  124. /*
  125.  * GetReq - Get the next avilable X request packet in the buffer and
  126.  * return it. 
  127.  *
  128.  * "name" is the name of the request, e.g. CreatePixmap, OpenFont, etc.
  129.  * "req" is the name of the request pointer.
  130.  *
  131.  */
  132.  
  133. #if defined(__STDC__) && !defined(UNIXCPP) 
  134. #define GetReq(name, req) \
  135.         WORD64ALIGN\
  136.     if ((dpy->bufptr + SIZEOF(x##name##Req)) > dpy->bufmax)\
  137.         _XFlush(dpy);\
  138.     req = (x##name##Req *)(dpy->last_req = dpy->bufptr);\
  139.     req->reqType = X_##name;\
  140.     req->length = (SIZEOF(x##name##Req))>>2;\
  141.     dpy->bufptr += SIZEOF(x##name##Req);\
  142.     dpy->request++
  143.  
  144. #else  /* non-ANSI C uses empty comment instead of "##" for token concatenation */
  145. #define GetReq(name, req) \
  146.         WORD64ALIGN\
  147.     if ((dpy->bufptr + SIZEOF(x/**/name/**/Req)) > dpy->bufmax)\
  148.         _XFlush(dpy);\
  149.     req = (x/**/name/**/Req *)(dpy->last_req = dpy->bufptr);\
  150.     req->reqType = X_/**/name;\
  151.     req->length = (SIZEOF(x/**/name/**/Req))>>2;\
  152.     dpy->bufptr += SIZEOF(x/**/name/**/Req);\
  153.     dpy->request++
  154. #endif
  155.  
  156. /* GetReqExtra is the same as GetReq, but allocates "n" additional
  157.    bytes after the request. "n" must be a multiple of 4!  */
  158.  
  159. #if defined(__STDC__) && !defined(UNIXCPP) 
  160. #define GetReqExtra(name, n, req) \
  161.         WORD64ALIGN\
  162.     if ((dpy->bufptr + SIZEOF(x##name##Req) + n) > dpy->bufmax)\
  163.         _XFlush(dpy);\
  164.     req = (x##name##Req *)(dpy->last_req = dpy->bufptr);\
  165.     req->reqType = X_##name;\
  166.     req->length = (SIZEOF(x##name##Req) + n)>>2;\
  167.     dpy->bufptr += SIZEOF(x##name##Req) + n;\
  168.     dpy->request++
  169. #else
  170. #define GetReqExtra(name, n, req) \
  171.         WORD64ALIGN\
  172.     if ((dpy->bufptr + SIZEOF(x/**/name/**/Req) + n) > dpy->bufmax)\
  173.         _XFlush(dpy);\
  174.     req = (x/**/name/**/Req *)(dpy->last_req = dpy->bufptr);\
  175.     req->reqType = X_/**/name;\
  176.     req->length = (SIZEOF(x/**/name/**/Req) + n)>>2;\
  177.     dpy->bufptr += SIZEOF(x/**/name/**/Req) + n;\
  178.     dpy->request++
  179. #endif
  180.  
  181.  
  182. /*
  183.  * GetResReq is for those requests that have a resource ID 
  184.  * (Window, Pixmap, GContext, etc.) as their single argument.
  185.  * "rid" is the name of the resource. 
  186.  */
  187.  
  188. #if defined(__STDC__) && !defined(UNIXCPP) 
  189. #define GetResReq(name, rid, req) \
  190.         WORD64ALIGN\
  191.     if ((dpy->bufptr + SIZEOF(xResourceReq)) > dpy->bufmax)\
  192.         _XFlush(dpy);\
  193.     req = (xResourceReq *) (dpy->last_req = dpy->bufptr);\
  194.     req->reqType = X_##name;\
  195.     req->length = 2;\
  196.     req->id = (rid);\
  197.     dpy->bufptr += SIZEOF(xResourceReq);\
  198.     dpy->request++
  199. #else
  200. #define GetResReq(name, rid, req) \
  201.         WORD64ALIGN\
  202.     if ((dpy->bufptr + SIZEOF(xResourceReq)) > dpy->bufmax)\
  203.         _XFlush(dpy);\
  204.     req = (xResourceReq *) (dpy->last_req = dpy->bufptr);\
  205.     req->reqType = X_/**/name;\
  206.     req->length = 2;\
  207.     req->id = (rid);\
  208.     dpy->bufptr += SIZEOF(xResourceReq);\
  209.     dpy->request++
  210. #endif
  211.  
  212. /*
  213.  * GetEmptyReq is for those requests that have no arguments
  214.  * at all. 
  215.  */
  216. #if defined(__STDC__) && !defined(UNIXCPP) 
  217. #define GetEmptyReq(name, req) \
  218.         WORD64ALIGN\
  219.     if ((dpy->bufptr + SIZEOF(xReq)) > dpy->bufmax)\
  220.         _XFlush(dpy);\
  221.     req = (xReq *) (dpy->last_req = dpy->bufptr);\
  222.     req->reqType = X_##name;\
  223.     req->length = 1;\
  224.     dpy->bufptr += SIZEOF(xReq);\
  225.     dpy->request++
  226. #else
  227. #define GetEmptyReq(name, req) \
  228.         WORD64ALIGN\
  229.     if ((dpy->bufptr + SIZEOF(xReq)) > dpy->bufmax)\
  230.         _XFlush(dpy);\
  231.     req = (xReq *) (dpy->last_req = dpy->bufptr);\
  232.     req->reqType = X_/**/name;\
  233.     req->length = 1;\
  234.     dpy->bufptr += SIZEOF(xReq);\
  235.     dpy->request++
  236. #endif
  237.  
  238.  
  239. #define SyncHandle() \
  240.     if (dpy->synchandler) (*dpy->synchandler)(dpy)
  241.  
  242. #define FlushGC(dpy, gc) \
  243.     if ((gc)->dirty) _XFlushGCCache((dpy), (gc))
  244. /*
  245.  * Data - Place data in the buffer and pad the end to provide
  246.  * 32 bit word alignment.  Transmit if the buffer fills.
  247.  *
  248.  * "dpy" is a pointer to a Display.
  249.  * "data" is a pinter to a data buffer.
  250.  * "len" is the length of the data buffer.
  251.  * we can presume buffer less than 2^16 bytes, so bcopy can be used safely.
  252.  */
  253. #ifdef DataRoutineIsProcedure
  254. extern void Data();
  255. #else
  256. #define Data(dpy, data, len) \
  257.     if (dpy->bufptr + (len) <= dpy->bufmax) {\
  258.         bcopy(data, dpy->bufptr, (int)len);\
  259.         dpy->bufptr += ((len) + 3) & ~3;\
  260.     } else\
  261.         _XSend(dpy, data, (long) len) /* Added cast. POHC 91/03/28 */
  262. #endif /* DataRoutineIsProcedure */
  263.  
  264.  
  265. /* Allocate bytes from the buffer.  No padding is done, so if
  266.  * the length is not a multiple of 4, the caller must be
  267.  * careful to leave the buffer aligned after sending the
  268.  * current request.
  269.  *
  270.  * "type" is the type of the pointer being assigned to.
  271.  * "ptr" is the pointer being assigned to.
  272.  * "n" is the number of bytes to allocate.
  273.  *
  274.  * Example: 
  275.  *    xTextElt *elt;
  276.  *    BufAlloc (xTextElt *, elt, nbytes)
  277.  */
  278.  
  279. #define BufAlloc(type, ptr, n) \
  280.     if (dpy->bufptr + (n) > dpy->bufmax) \
  281.         _XFlush (dpy); \
  282.     ptr = (type) dpy->bufptr; \
  283.     dpy->bufptr += (n);
  284.  
  285. /*
  286.  * provide emulation routines for smaller architectures
  287.  */
  288. #ifndef WORD64
  289. #define Data16(dpy, data, len) Data((dpy), (char *)(data), (len))
  290. #define Data32(dpy, data, len) Data((dpy), (char *)(data), (len))
  291. #define _XRead16Pad(dpy, data, len) _XReadPad((dpy), (char *)(data), (len))
  292. #define _XRead16(dpy, data, len) _XRead((dpy), (char *)(data), (len))
  293. #define _XRead32(dpy, data, len) _XRead((dpy), (char *)(data), (len))
  294. #endif /* not WORD64 */
  295.  
  296. #define PackData16(dpy,data,len) Data16 (dpy, data, len)
  297. #define PackData32(dpy,data,len) Data32 (dpy, data, len)
  298.  
  299. /* Xlib manual is bogus */
  300. #define PackData(dpy,data,len) PackData16 (dpy, data, len)
  301.  
  302. #define min(a,b)  (((a) < (b)) ? (a) : (b))
  303. #define max(a,b) (((a) > (b)) ? (a) : (b))
  304.  
  305. #define CI_NONEXISTCHAR(cs) (((cs)->width == 0) && \
  306.                  ((cs)->rbearing == 0) && \
  307.                  ((cs)->lbearing == 0))
  308.  
  309. /* 
  310.  * CI_GET_CHAR_INFO_1D - return the charinfo struct for the indicated 8bit
  311.  * character.  If the character is in the column and exists, then return the
  312.  * appropriate metrics (note that fonts with common per-character metrics will
  313.  * return min_bounds).  If none of these hold true, try again with the default
  314.  * char.
  315.  */
  316. #define CI_GET_CHAR_INFO_1D(fs,col,def,cs) \
  317. { \
  318.     cs = def; \
  319.     if (col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2) { \
  320.     if (fs->per_char == NULL) { \
  321.         cs = &fs->min_bounds; \
  322.     } else { \
  323.         cs = &fs->per_char[(col - fs->min_char_or_byte2)]; \
  324.         if (CI_NONEXISTCHAR(cs)) cs = def; \
  325.     } \
  326.     } \
  327. }
  328.  
  329. #define CI_GET_DEFAULT_INFO_1D(fs,cs) \
  330.   CI_GET_CHAR_INFO_1D (fs, fs->default_char, NULL, cs)
  331.  
  332.  
  333.  
  334. /*
  335.  * CI_GET_CHAR_INFO_2D - return the charinfo struct for the indicated row and 
  336.  * column.  This is used for fonts that have more than row zero.
  337.  */
  338. #define CI_GET_CHAR_INFO_2D(fs,row,col,def,cs) \
  339. { \
  340.     cs = def; \
  341.     if (row >= fs->min_byte1 && row <= fs->max_byte1 && \
  342.     col >= fs->min_char_or_byte2 && col <= fs->max_char_or_byte2) { \
  343.     if (fs->per_char == NULL) { \
  344.         cs = &fs->min_bounds; \
  345.     } else { \
  346.         cs = &fs->per_char[((row - fs->min_byte1) * \
  347.                     (fs->max_char_or_byte2 - \
  348.                  fs->min_char_or_byte2 + 1)) + \
  349.                    (col - fs->min_char_or_byte2)]; \
  350.         if (CI_NONEXISTCHAR(cs)) cs = def; \
  351.         } \
  352.     } \
  353. }
  354.  
  355. #define CI_GET_DEFAULT_INFO_2D(fs,cs) \
  356. { \
  357.     unsigned int r = (fs->default_char >> 8); \
  358.     unsigned int c = (fs->default_char & 0xff); \
  359.     CI_GET_CHAR_INFO_2D (fs, r, c, NULL, cs); \
  360. }
  361.  
  362.  
  363.  
  364.  
  365.  
  366. #ifdef MUSTCOPY
  367.  
  368. /* a little bit of magic */
  369. #define OneDataCard32(dpy,dstaddr,srcvar) \
  370.   { dpy->bufptr -= 4; Data32 (dpy, (char *) &(srcvar), 4); }
  371.  
  372. #define STARTITERATE(tpvar,type,start,endcond,decr) \
  373.   { register char *cpvar; \
  374.   for (cpvar = (char *) start; endcond; cpvar = NEXTPTR(cpvar,type), decr) { \
  375.     type dummy; bcopy (cpvar, (char *) &dummy, SIZEOF(type)); \
  376.     tpvar = (type *) cpvar;
  377. #define ENDITERATE }}
  378.  
  379. #else
  380.  
  381. /* srcvar must be a variable for large architecture version */
  382. #define OneDataCard32(dpy,dstaddr,srcvar) \
  383.   { *(unsigned long *)(dstaddr) = (srcvar); }
  384.  
  385. #define STARTITERATE(tpvar,type,start,endcond,decr) \
  386.   for (tpvar = (type *) start; endcond; tpvar++, decr) {
  387. #define ENDITERATE }
  388.  
  389. #endif /* MUSTCOPY - used machines whose C structs don't line up with proto */
  390.  
  391.  
  392. /* extension hooks */
  393.  
  394. typedef int (*XExtGCHandler) (      /* WARNING, this type not in Xlib spec */
  395. #if NeedFunctionPtrPrototypes /* POHC 91/04/16 */
  396.     Display *           /* display */,
  397.     GC                  /* gc */,
  398.     XExtCodes *         /* codes */
  399. #endif
  400. );
  401.  
  402. typedef int (*XExtFontHandler) (      /* WARNING, this type not in Xlib spec */
  403. #if NeedFunctionPtrPrototypes /* POHC 91/04/16 */
  404.     Display *           /* display */,
  405.     XFontStruct *       /* fs */,
  406.     XExtCodes *         /* codes */
  407. #endif
  408. );
  409.  
  410. typedef int (*XExtHandler) (      /* WARNING, this type not in Xlib spec */
  411. #if NeedFunctionPtrPrototypes /* POHC 91/04/16 */
  412.     Display *           /* display */,
  413.     XExtCodes *         /* codes */
  414. #endif
  415. );
  416.  
  417.  
  418. typedef Status (*XExtWireHandler) (      /* WARNING, this type not in Xlib spec */
  419. #if NeedFunctionPtrPrototypes /* POHC 91/04/16 */
  420.     Display *           /* display */,
  421.     XEvent *            /* re */,
  422.     struct _xEvents *   /* event */
  423. #endif
  424. );
  425.  
  426. typedef int (*XExtErrorHandler) (      /* WARNING, this type not in Xlib spec */
  427. #if NeedFunctionPtrPrototypes /* POHC 91/04/16 */
  428.     Display *           /* display */,
  429.     xError *            /* err */,
  430.     XExtCodes *         /* codes */,
  431.     int *               /* ret_code */
  432. #endif
  433. );
  434.  
  435. typedef char * (*XExtErrorStringHandler) (      /* WARNING, this type not in Xlib spec */
  436. #if NeedFunctionPtrPrototypes /* POHC 91/04/16 */
  437.     Display *           /* display */,
  438.     int                 /* code */,
  439.     XExtCodes *         /* codes */,
  440.     char *              /* buffer */,
  441.     int                 /* nbytes */
  442. #endif
  443. );
  444.  
  445. extern XExtGCHandler XESetCreateGC(
  446. #if (NeedFunctionPrototypes || NeedFunctionPtrPrototypes) /* POHC 91/04/16 */
  447.     Display*        /* display */,
  448.     int            /* extension */,
  449.     XExtGCHandler        /* proc */
  450. #endif
  451. );
  452.  
  453. extern XExtGCHandler XESetCopyGC(
  454. #if (NeedFunctionPrototypes || NeedFunctionPtrPrototypes) /* POHC 91/04/16 */
  455.     Display*        /* display */,
  456.     int            /* extension */,
  457.     XExtGCHandler        /* proc */          
  458. #endif
  459. );
  460.  
  461. extern XExtGCHandler XESetFlushGC(
  462. #if (NeedFunctionPrototypes || NeedFunctionPtrPrototypes) /* POHC 91/04/16 */
  463.     Display*        /* display */,
  464.     int            /* extenstion */,
  465.     XExtGCHandler        /* proc */         
  466. #endif
  467. );
  468.  
  469. extern XExtGCHandler XESetFreeGC(
  470. #if (NeedFunctionPrototypes || NeedFunctionPtrPrototypes) /* POHC 91/04/16 */
  471.     Display*        /* display */,
  472.     int            /* extension */,
  473.     XExtGCHandler        /* proc */         
  474. #endif
  475. );
  476.  
  477. extern XExtFontHandler XESetCreateFont(
  478. #if (NeedFunctionPrototypes || NeedFunctionPtrPrototypes) /* POHC 91/04/16 */
  479.     Display*        /* display */,
  480.     int            /* extension */,
  481.     XExtFontHandler    /* proc */    
  482. #endif
  483. );
  484.  
  485. extern XExtFontHandler XESetFreeFont(
  486. #if (NeedFunctionPrototypes || NeedFunctionPtrPrototypes) /* POHC 91/04/16 */
  487.     Display*        /* display */,
  488.     int            /* extension */,
  489.     XExtFontHandler    /* proc */    
  490. #endif
  491. ); 
  492.  
  493. extern XExtHandler XESetCloseDisplay(
  494. #if (NeedFunctionPrototypes || NeedFunctionPtrPrototypes) /* POHC 91/04/16 */
  495.     Display*        /* display */,
  496.     int            /* extension */,
  497.     XExtHandler        /* proc */    
  498. #endif
  499. );
  500.  
  501. extern XExtErrorHandler XESetError(
  502. #if (NeedFunctionPrototypes || NeedFunctionPtrPrototypes) /* POHC 91/04/16 */
  503.     Display*        /* display */,
  504.     int            /* extension */,
  505.     XExtErrorHandler    /* proc */    
  506. #endif
  507. );
  508.  
  509. extern XExtErrorStringHandler XESetErrorString(
  510. #if (NeedFunctionPrototypes || NeedFunctionPtrPrototypes) /* POHC 91/04/16 */
  511.     Display*            /* display */,
  512.     int                /* extension */,
  513.     XExtErrorStringHandler    /* proc */           
  514. #endif
  515. );
  516.  
  517. extern XExtWireHandler XESetWireToEvent(
  518. #if (NeedFunctionPrototypes || NeedFunctionPtrPrototypes) /* POHC 91/04/16 */
  519.     Display*        /* display */,
  520.     int            /* event_number */,
  521.     XExtWireHandler    /* proc */    
  522. #endif
  523. );
  524.  
  525. extern XExtWireHandler XESetEventToWire(
  526. #if (NeedFunctionPrototypes || NeedFunctionPtrPrototypes) /* POHC 91/04/16 */
  527.     Display*        /* display */,
  528.     int            /* event_number */,
  529.     XExtWireHandler    /* proc */   
  530. #endif
  531. );
  532.  
  533. extern void _XWaitForWritable(
  534. #if NeedFunctionPrototypes
  535. Display * /* dpy */
  536. #endif
  537. );
  538.  
  539. extern int _XDisconnectDisplay(
  540. #if NeedFunctionPrototypes
  541. int /* server */
  542. #endif
  543. );
  544.  
  545. #ifdef __cplusplus
  546. }                        /* for C++ V2.0 */
  547. #endif
  548.  
  549.  
  550.